<?php

class wallet_model extends cms_model {

    public function __construct() {
        parent::__construct();
        $this->table = 'wallet';
    }

    public function filter($limit = FALSE, $order = FALSE) {
        $config['total_rows'] = $this->get(array('user_id' => $this->user_id), TRUE);
        if ($limit)
            $config['per_page'] = $limit;
        else
            $config['per_page'] = 30;
        if (!$order || $order == 'up') {
            $this->order = array('id' => 'desc');
        } else {
            $this->order = array('id' => 'asc');
        }
        $data['result'] = $this->get(array('user_id' => $this->user_id), FALSE, 'result', $config['per_page']);
        return $data;
    }

    function aftersave($id) {
        if(isset($this->data['bank_name']) && isset($this->data['sender_name']) && isset($this->data['account_number'])){
            $note = false;
            if(isset($this->data['note']))
                $note = $this->data['note'];
        $this->db->insert('wallet_bank', array(
            'wallet_id' => $id,
            'bank_name' => $this->data['bank_name'],
            'sender_name' => $this->data['sender_name'],
            'account_number' => $this->data['account_number'],
            'note' => $note,
        ));
        }
    }
}
